<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Title="3D Fractal using F# and WPF" Width="800" Height="800">
  <Viewport3D Name="view">
    <Viewport3D.Camera>
      <PerspectiveCamera x:Name="cam" UpDirection="0,1,0" Position="100,100,100" LookDirection="0, 0, -1" FieldOfView="60" />
    </Viewport3D.Camera>
    <Viewport3D.Children>

      <ModelVisual3D x:Name="fractal" />
      
      <ModelVisual3D>
        <ModelVisual3D.Content>
          <!-- spot light bound to the camera -->
          <SpotLight x:Name="light" InnerConeAngle="0" OuterConeAngle="120" Color="#20D040" Range="1000">
            <SpotLight.Direction>
              <Binding ElementName="cam" Path="LookDirection" />
            </SpotLight.Direction>
            <SpotLight.Position>
              <Binding ElementName="cam" Path="Position" />
            </SpotLight.Position>
          </SpotLight>
        </ModelVisual3D.Content>
      </ModelVisual3D>
      
    </Viewport3D.Children>
    <Viewport3D.Triggers>
      <EventTrigger RoutedEvent="Viewport3D.Loaded">
        <BeginStoryboard>
          <Storyboard>
            <!-- move to fractal -->
            <Point3DAnimation Storyboard.TargetName="cam" Storyboard.TargetProperty="Position"
                              From="0,0,100" To="0,0,27" Duration="0:0:4" RepeatBehavior="1x"/>
            <!-- repeat fractal animation -->
            <ParallelTimeline RepeatBehavior="Forever" BeginTime="0:0:4">
              <!-- move forward -->
              <Point3DAnimation Storyboard.TargetName="cam" Storyboard.TargetProperty="Position"
                                From="0,0,27" To="0,0,-9" Duration="0:0:4" RepeatBehavior="1x" BeginTime="0:0:0"/>
              <!-- rotate camera -->
              <Vector3DAnimation Storyboard.TargetName="cam" Storyboard.TargetProperty="LookDirection"
                                 From="0, 0, -1" To="0, 1, 0" Duration="0:0:1" RepeatBehavior="1x" BeginTime="0:0:3"/>
              
              <!-- reset camera -->              
              <Vector3DAnimationUsingKeyFrames Storyboard.TargetName="cam" Storyboard.TargetProperty="LookDirection" BeginTime="0:0:4">
                <Vector3DAnimationUsingKeyFrames.KeyFrames>
                  <DiscreteVector3DKeyFrame Value="0, 0, -1" KeyTime="0:0:0" />
                </Vector3DAnimationUsingKeyFrames.KeyFrames>
              </Vector3DAnimationUsingKeyFrames>                           
              <!-- move forward -->
              <Point3DAnimation Storyboard.TargetName="cam" Storyboard.TargetProperty="Position"
                                From="0,0,27" To="0,0,-9" Duration="0:0:4" RepeatBehavior="1x" BeginTime="0:0:4"/>
              <!-- rotate camera -->
              <Vector3DAnimation Storyboard.TargetName="cam" Storyboard.TargetProperty="LookDirection"
                                 From="0, 0, -1" To="0, -1, 0" Duration="0:0:1" RepeatBehavior="1x" BeginTime="0:0:7"/>
            </ParallelTimeline>
          </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Viewport3D.Triggers>
  </Viewport3D>
  
</Window>
